package io.jft.doll.model.viewModel

import android.arch.lifecycle.MutableLiveData
import com.g.base.extend.switchMap
import com.g.base.viewModel.BaseViewModel
import io.jft.doll.room.repository.MessageRepository

/**
 * Created by G on 2017/11/26 0026.
 */
class MessageViewModel : BaseViewModel() {
    private val messageRepository by lazy { MessageRepository() }

    private val operateMessageList by lazy { MutableLiveData<String>() }
    fun obsMessageList() = operateMessageList.switchMap { messageRepository.getMessageList(0, 30, it) }
    fun operateMessageList(type: String) {
        operateMessageList.value = type
    }

    fun markMessageRead(id: String, type: String) = messageRepository.markMessageRead(id, type)

    fun delMessage(id: String, type: String) = messageRepository.delMessage(id, type)

    private val operateMessageCount by lazy { MutableLiveData<Boolean>() }
    fun operateMessageCount() {
        operateMessageCount.value = true
    }

    fun obsMessageCount() = operateMessageCount.switchMap {
        messageRepository.getMessageCount()
    }
}